#ifndef DATABASE_H
#define DATABASE_H

#include <list>
#include <string>
#include <algorithm>

#include "item.h"

class database
{
public:
    typedef std::list<basic_item*> elems_type;
    typedef elems_type::iterator iterator;

    static void insert(basic_item* val);

    static iterator find_id(const std::string& id);
    static void remove_id(const std::string& id);

    static iterator begin();
    static iterator end();

    static void save();
    static void init();

    static std::string alloc_id();

    static int get_ids();

private:
    static int allocated_ids;
    static std::list<basic_item*> elems;
};

struct id_equal
{
    std::string id_base;

    id_equal(std::string init_val)
    {
        id_base = init_val;
    }

    bool operator()(basic_item* other)
    {
        return other->get_id().value == id_base;
    }
};

#endif // !DATABASE_H
